/**
 *
 */
package uy.edu.um.taller2;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JDesktopPane;
import java.awt.Rectangle;

/**
 * @author pegardan
 *
 */
public class JMainFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JMenuBar jMyMenuBar = null;
	private JMenu jMenuFile = null;
	private JMenu jMenuAbout = null;
	private JMenuItem jMenuItemExit = null;
	private JMenuItem jMenuItemClients = null;
	private JDesktopPane jDesktopPane = null;
	private JInternalFrameABMClients jInternalFrameABMClients = null;

	/**
	 * This is the default constructor
	 */
	public JMainFrame() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 *
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setJMenuBar(getJMyMenuBar());
		this.setContentPane(getJContentPane());
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		this.setTitle("JFrame");
	}

	/**
	 * This method initializes jContentPane
	 *
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJDesktopPane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jMyMenuBar
	 *
	 * @return javax.swing.JMenuBar
	 */
	private JMenuBar getJMyMenuBar() {
		if (jMyMenuBar == null) {
			jMyMenuBar = new JMenuBar();
			jMyMenuBar.add(getJMenuFile());
			jMyMenuBar.add(getJMenuAbout());
		}
		return jMyMenuBar;
	}

	/**
	 * This method initializes jMenuFile
	 *
	 * @return javax.swing.JMenu
	 */
	private JMenu getJMenuFile() {
		if (jMenuFile == null) {
			jMenuFile = new JMenu();
			jMenuFile.setText("Archivo");
			jMenuFile.add(getJMenuItemExit());
			jMenuFile.add(getJMenuItemClients());
		}
		return jMenuFile;
	}

	/**
	 * This method initializes jMenuAbout
	 *
	 * @return javax.swing.JMenu
	 */
	private JMenu getJMenuAbout() {
		if (jMenuAbout == null) {
			jMenuAbout = new JMenu();
			jMenuAbout.setText("Acerca De");
		}
		return jMenuAbout;
	}

	/**
	 * This method initializes jMenuItemExit
	 *
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItemExit() {
		if (jMenuItemExit == null) {
			jMenuItemExit = new JMenuItem();
			jMenuItemExit.setText("Salir");
			jMenuItemExit.addActionListener(new ActionListener() {

				public void actionPerformed(ActionEvent e) {

					int nOption = JOptionPane.showConfirmDialog(JMainFrame.this, "¿ Esta seguro que desea salir ?");

					switch (nOption) {

						case JOptionPane.YES_OPTION:

							System.exit(0);

					}

				}

			});
		}
		return jMenuItemExit;
	}

	/**
	 * This method initializes jMenuItemClients
	 *
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItemClients() {
		if (jMenuItemClients == null) {
			jMenuItemClients = new JMenuItem();
			jMenuItemClients.setText("Clientes");
			jMenuItemClients.addActionListener(new ActionListener() {

				public void actionPerformed(ActionEvent e) {
					getJDesktopPane().add(getJInternalFrameABMClients());
					getJInternalFrameABMClients().pack();
					getJInternalFrameABMClients().setVisible(true);

				}

			});
		}
		return jMenuItemClients;
	}

	/**
	 * This method initializes jDesktopPane
	 *
	 * @return javax.swing.JDesktopPane
	 */
	private JDesktopPane getJDesktopPane() {
		if (jDesktopPane == null) {
			jDesktopPane = new JDesktopPane();

		}
		return jDesktopPane;
	}

	/**
	 * This method initializes jInternalFrameABMClients
	 *
	 * @return uy.edu.um.taller2.JInternalFrameABMClients
	 */
	private JInternalFrameABMClients getJInternalFrameABMClients() {
		if (jInternalFrameABMClients == null) {
			jInternalFrameABMClients = new JInternalFrameABMClients();
		}
		return jInternalFrameABMClients;
	}

}
